DELETE FROM QVW_WBBST WHERE SVDATE=TO_CHAR(SYSDATE,'YYYYMMDD')
GO
DROP TABLE INTEX.QVW_WBBST
GO

CREATE TABLE QVW_WBBST
AS
--INSERT INTO QVW_WBBST
SELECT DISTINCT TO_CHAR(SYSDATE,'YYYYMMDD') AS SVDATE,WBBLO AS LO,WBBLB AS LB,WBBWAKZ AS ARTST,
WBBART AS PART,WBBVAR AS PVAR,
WBBFARBE AS PCOLOR,
WBBDESS AS PDESS,
WBBCOLORIT AS PDCWY,
WBBBESCHICH AS PFINISH,
SUM(WBBISTKLG*0.001) AS STLENG,
SUM(WBBTSTKLG*0.001) AS STLLENG,
SUM(WBBSGEW*0.001) AS STWEIGHT,
WBBZENSUR||WBBZENSURKZ AS QG,
WBBAUFTYP AS AUFTYP,
WBBAUFKRS AS PKRS,
WBBAUFLFD AS PLFD,
WBBAUFPOS AS PPOS,
MAX(WBBAFOLGEVON) AS PFSTEP,
MAX(KST) AS KST,
MAX(KOPEBEZ) AS KOPEBEZ,
MAX(MTYPE) AS MTYPE,
0.0 AS MSTQTY,
0.0 AS MOVEIN,
0.0 AS MOVEOUT,
0.0 AS MADJUST,
WBBEINDAT AS IDATE
 FROM WBBST B LEFT JOIN QVW_ABFOLGE F ON B.WBBAUFTYP=F.AUFTYP AND B.WBBAUFKRS=F.PKRS AND B.WBBAUFLFD=F.PLFD AND B.WBBAUFPOS=F.PPOS AND B.WBBAFOLGEVON=F.PFSTEP
   WHERE WBBMANDANT='00'
GROUP BY WBBMANDANT,WBBLO,WBBLB,WBBWAKZ,WBBART,WBBVAR,WBBFARBE,WBBDESS,WBBCOLORIT,WBBBESCHICH,
WBBAUFTYP,WBBAUFKRS,WBBAUFLFD,WBBAUFPOS,WBBAFOLGEVON,WBBEINDAT,WBBZENSUR,WBBZENSURKZ
GO

DELETE FROM QVW_BABST WHERE SVDATE=TO_CHAR(SYSDATE,'YYYYMMDD')
GO
DROP TABLE INTEX.QVW_BABST
GO
CREATE TABLE QVW_BABST
AS
--INSERT INTO QVW_BABST
SELECT DISTINCT
TO_CHAR(SYSDATE,'YYYYMMDD') AS SVDATE,
'K' AS ARTST, BMKART AS PART,BMKVAR AS PVAR,BMFARBE AS PCOLOR,'          ' AS PDESS,'          ' AS PDCWY,'          ' AS PFINISH,'       ' AS PSIZE,
BMLO AS LO,BMLB AS LB,
0.0 AS MSTQTY,
0.0 AS MOVEIN,
0.0 AS MOVEOUT,
0.0 AS MADJUST,
SUM(BMSOLLLG*0.001) AS STLENG,
BMAUFTYP AS AUFTYP,
BMAUFTYP||BMAUFKRS||BMAUFLFD AS KAUF,
BMAUFTYP||BMAUFKRS||BMAUFLFD||BMAUFPOS AS PAUF,
BMAUFKRS  AS PKRS, BMAUFLFD  AS PLFD,BMAUFPOS AS PPOS
FROM BABST WHERE BMMANDANT='00'
GROUP BY BMMANDANT,BMLO,BMLB,BMKART,BMKVAR,BMFARBE,BMAUFTYP,BMAUFKRS,BMAUFLFD,BMAUFPOS
GO
DROP TABLE QVW_ZUTEI
GO
CREATE TABLE QVW_ZUTEI
AS
SELECT DISTINCT
'G' AS ARTST, ZUART AS PART,ZUVAR AS PVAR,ZUFARBE AS PCOLOR,'          ' AS PDESS,'          ' AS PDCWY,'          ' AS PFINISH,'       ' AS PSIZE,
ZULO AS LO,ZULB AS LB,
'V' AS AUFTYP,
ZUAUFKRS AS PKRS,
ZUAUFLFD AS PLFD,
ZUAUFPOS AS PPOS,
SUM(ZUEINTKG*0.001) AS STWEIGHT
FROM ZUTEI B WHERE ZUMANDANT='00'
GROUP BY ZUMANDANT,ZULO,ZULB,ZUART,ZUVAR,ZUFARBE,ZUAUFKRS,ZUAUFLFD,ZUAUFPOS
GO

DELETE FROM QVW_GLLG WHERE SVDATE=TO_CHAR(SYSDATE,'YYYYMMDD')
GO
DROP TABLE INTEX.QVW_GLLG
GO
CREATE TABLE QVW_GLLG
AS
--INSERT INTO QVW_GLLG
SELECT DISTINCT
TO_CHAR(SYSDATE,'YYYYMMDD') AS SVDATE,
'G' AS ARTST, GPBART AS PART,GPBVAR AS PVAR,GPBFARBE AS PCOLOR,'          ' AS PDESS,'          ' AS PDCWY,'          ' AS PFINISH,'       ' AS PSIZE,
GLLO AS LO,GLLB AS LB,
WBBAUFTYP AS AUFTYP,
WBBAUFKRS AS PKRS,
WBBAUFLFD AS PLFD,
WBBAUFPOS AS PPOS,
MAX(WBBAFOLGEVON) AS PFSTEP,
MAX(KST) AS KST,
MAX(KOPEBEZ) AS KOPEBEZ,
MAX(MTYPE) AS MTYPE,
0.0 AS MSTQTY,
0.0 AS MOVEIN,
0.0 AS MOVEOUT,
0.0 AS MADJUST,
SUM(GLBSTKG*0.001) AS STWEIGHT
FROM GLLG B JOIN GPBST ON GLPARTIE=GPBPARTIE
LEFT JOIN QVW_ABFOLGE F ON B.WBBAUFTYP=F.AUFTYP AND B.WBBAUFKRS=F.PKRS AND B.WBBAUFLFD=F.PLFD AND B.WBBAUFPOS=F.PPOS AND B.WBBAFOLGEVON=F.PFSTEP
 WHERE GLMANDANT='00'
GROUP BY GLMANDANT,GLLO,GLLB,GPBART,GPBVAR,GPBFARBE
GO

DELETE FROM QVW_MBST WHERE SVDATE=TO_CHAR(SYSDATE,'YYYYMMDD')
GO
DROP TABLE INTEX.QVW_MBST
GO
CREATE TABLE QVW_MBST
AS
--INSERT INTO QVW_GLLG
SELECT DISTINCT
TO_CHAR(SYSDATE,'YYYYMMDD') AS SVDATE,
'M' AS ARTST, MBMAT AS PART,MBVAR AS PVAR,'          ' AS PCOLOR,'          ' AS PDESS,'          ' AS PDCWY,'          ' AS PFINISH,'       ' AS PSIZE,
MBLO AS LO,MBLB AS LB,
0.0 AS MSTQTY,
0.0 AS MOVEIN,
0.0 AS MOVEOUT,
0.0 AS MADJUST,
SUM(MBME*0.001) AS STWEIGHT
FROM MBST
 WHERE MBMANDANT='00'
GROUP BY MBMANDANT,MBLO,MBLB,MBMAT,MBVAR
GO
DELETE FROM QVW_FBST WHERE SVDATE=TO_CHAR(SYSDATE,'YYYYMMDD')
GO
DROP TABLE INTEX.QVW_FBST
GO
CREATE TABLE QVW_FBST
AS
--INSERT INTO QVW_GLLG
SELECT DISTINCT
TO_CHAR(SYSDATE,'YYYYMMDD') AS SVDATE,
'T' AS ARTST, FBART AS PART,FBVAR AS PVAR,FBFARBE AS PCOLOR,'          ' AS PDESS,'          ' AS PDCWY,'          ' AS PFINISH,FBGROE AS PSIZE,
FBLO AS LO,FBLB AS LB,
0.0 AS MSTQTY,
0.0 AS MOVEIN,
0.0 AS MOVEOUT,
0.0 AS MADJUST,
SUM(FBME) AS STWEIGHT
FROM FBST  WHERE FBMANDANT='00'
GROUP BY FBMANDANT,FBLO,FBLB,FBART,FBVAR,FBFARBE,FBGROE
GO

UPDATE QVW_WBBST B SET MOVEIN=
(SELECT SUM(UQTY) FROM QVW_MCOST M WHERE
M.BS IN ('01','10','11','21','13')  AND RTRIM(B.SVDATE)=RTRIM(M.WDATE) AND B.LO=M.LO AND B.LB=M.LB
AND RTRIM(B.PART)=RTRIM(M.PART) AND RTRIM(B.PCOLOR)=RTRIM(M.PCOLOR)AND RTRIM(B.PFINISH)=RTRIM(M.PFINISH) AND RTRIM(B.PDESS)=RTRIM(M.PDESS) AND B.ARTST=M.ARTST)
WHERE EXISTS
(SELECT 1 FROM QVW_MCOST M WHERE  M.BS IN ('01','10','11','21','13') AND RTRIM(B.SVDATE)=RTRIM(M.WDATE) AND B.LO=M.LO AND B.LB=M.LB
AND RTRIM(B.PART)=RTRIM(M.PART) AND RTRIM(B.PCOLOR)=RTRIM(M.PCOLOR)AND RTRIM(B.PFINISH)=RTRIM(M.PFINISH) AND RTRIM(B.PDESS)=RTRIM(M.PDESS) AND B.ARTST=M.ARTST)
GO
UPDATE QVW_WBBST B SET MOVEOUT=
(SELECT SUM(UQTY) FROM QVW_MCOST M WHERE
M.BS IN ( '12','20','22','23','26','58') AND RTRIM(B.SVDATE)=RTRIM(M.WDATE) AND B.LO=M.LO AND B.LB=M.LB
AND RTRIM(B.PART)=RTRIM(M.PART) AND RTRIM(B.PCOLOR)=RTRIM(M.PCOLOR)AND RTRIM(B.PFINISH)=RTRIM(M.PFINISH) AND RTRIM(B.PDESS)=RTRIM(M.PDESS) AND B.ARTST=M.ARTST)
WHERE EXISTS
(
SELECT 1 FROM QVW_MCOST M WHERE  M.BS IN ( '12','20','22','23','26','58') AND RTRIM(B.SVDATE)=RTRIM(M.WDATE) AND B.LO=M.LO AND B.LB=M.LB
AND RTRIM(B.PART)=RTRIM(M.PART) AND RTRIM(B.PCOLOR)=RTRIM(M.PCOLOR)AND RTRIM(B.PFINISH)=RTRIM(M.PFINISH) AND RTRIM(B.PDESS)=RTRIM(M.PDESS) AND B.ARTST=M.ARTST)
GO
UPDATE QVW_WBBST B SET MADJUST=
(SELECT SUM(UQTY) FROM QVW_MCOST M WHERE
M.BS NOT IN ('01','10','11','21','13','12','20','22','23','26','58') AND RTRIM(B.SVDATE)=RTRIM(M.WDATE) AND B.LO=M.LO AND B.LB=M.LB
AND RTRIM(B.PART)=RTRIM(M.PART) AND RTRIM(B.PCOLOR)=RTRIM(M.PCOLOR)AND RTRIM(B.PFINISH)=RTRIM(M.PFINISH) AND RTRIM(B.PDESS)=RTRIM(M.PDESS) AND B.ARTST=M.ARTST)
WHERE EXISTS
(SELECT 1 FROM QVW_MCOST M WHERE  M.BS NOT IN ('01','10','11','21','13','12','20','22','23','26','58') AND RTRIM(B.SVDATE)=RTRIM(M.WDATE) AND B.LO=M.LO AND B.LB=M.LB
AND RTRIM(B.PART)=RTRIM(M.PART) AND RTRIM(B.PCOLOR)=RTRIM(M.PCOLOR)AND RTRIM(B.PFINISH)=RTRIM(M.PFINISH) AND RTRIM(B.PDESS)=RTRIM(M.PDESS) AND B.ARTST=M.ARTST)
GO

UPDATE QVW_GLLG B SET MOVEIN=
(SELECT SUM(UQTY) FROM QVW_MCOST M WHERE
M.BS IN ('01','10','11','21','13')  AND RTRIM(B.SVDATE)=RTRIM(M.WDATE) AND B.LO=M.LO AND B.LB=M.LB
AND RTRIM(B.PART)=RTRIM(M.PART) AND RTRIM(B.PVAR)=RTRIM(M.PVAR) AND RTRIM(B.PCOLOR)=RTRIM(M.PCOLOR)AND B.ARTST=M.ARTST)
WHERE EXISTS
(SELECT 1 FROM QVW_MCOST M WHERE  M.BS IN ('01','10','11','21','13') AND RTRIM(B.SVDATE)=RTRIM(M.WDATE) AND B.LO=M.LO AND B.LB=M.LB
AND RTRIM(B.PART)=RTRIM(M.PART) AND RTRIM(B.PVAR)=RTRIM(M.PVAR) AND RTRIM(B.PCOLOR)=RTRIM(M.PCOLOR)AND B.ARTST=M.ARTST)
GO

UPDATE QVW_GLLG B SET MOVEOUT=
(SELECT SUM(UQTY) FROM QVW_MCOST M WHERE
M.BS IN ('12','20','22','23','26','58') AND RTRIM(B.SVDATE)=RTRIM(M.WDATE) AND B.LO=M.LO AND B.LB=M.LB
AND RTRIM(B.PART)=RTRIM(M.PART) AND RTRIM(B.PVAR)=RTRIM(M.PVAR) AND RTRIM(B.PCOLOR)=RTRIM(M.PCOLOR)AND B.ARTST=M.ARTST)
WHERE EXISTS
(SELECT 1 FROM QVW_MCOST M WHERE  M.BS IN ('12','20','22','23','26','58') AND RTRIM(B.SVDATE)=RTRIM(M.WDATE) AND B.LO=M.LO AND B.LB=M.LB
AND RTRIM(B.PART)=RTRIM(M.PART) AND RTRIM(B.PVAR)=RTRIM(M.PVAR) AND RTRIM(B.PCOLOR)=RTRIM(M.PCOLOR)AND B.ARTST=M.ARTST)
GO
UPDATE QVW_GLLG B SET MADJUST=
(SELECT SUM(UQTY) FROM QVW_MCOST M WHERE
M.BS NOT IN ('01','10','11','21','13','12','20','22','23','26','58') AND RTRIM(B.SVDATE)=RTRIM(M.WDATE) AND B.LO=M.LO AND B.LB=M.LB
AND RTRIM(B.PART)=RTRIM(M.PART) AND RTRIM(B.PVAR)=RTRIM(M.PVAR) AND RTRIM(B.PCOLOR)=RTRIM(M.PCOLOR)AND B.ARTST=M.ARTST)
WHERE EXISTS
(SELECT 1 FROM QVW_MCOST M WHERE  M.BS NOT IN ('01','10','11','21','13','12','20','22','23','26','58') AND RTRIM(B.SVDATE)=RTRIM(M.WDATE) AND B.LO=M.LO AND B.LB=M.LB
AND RTRIM(B.PART)=RTRIM(M.PART) AND RTRIM(B.PVAR)=RTRIM(M.PVAR) AND RTRIM(B.PCOLOR)=RTRIM(M.PCOLOR)AND B.ARTST=M.ARTST)
GO

UPDATE QVW_MBST B SET MOVEIN=
(SELECT SUM(UQTY) FROM QVW_MCOST M WHERE
M.BS IN ('01','10','11','21','13')  AND RTRIM(B.SVDATE)=RTRIM(M.WDATE) AND B.LO=M.LO AND B.LB=M.LB
AND RTRIM(B.PART)=RTRIM(M.PART) AND RTRIM(B.PVAR)=RTRIM(M.PVAR) AND B.ARTST=M.ARTST)
WHERE EXISTS
(SELECT 1 FROM QVW_MCOST M WHERE  M.BS IN ('01','10','11','21','13') AND RTRIM(B.SVDATE)=RTRIM(M.WDATE) AND B.LO=M.LO AND B.LB=M.LB
AND RTRIM(B.PART)=RTRIM(M.PART) AND RTRIM(B.PVAR)=RTRIM(M.PVAR) AND B.ARTST=M.ARTST)
GO

UPDATE QVW_MBST B SET MOVEOUT=
(SELECT SUM(UQTY) FROM QVW_MCOST M WHERE
M.BS IN ('12','20','22','23','26','58') AND RTRIM(B.SVDATE)=RTRIM(M.WDATE) AND B.LO=M.LO AND B.LB=M.LB
AND RTRIM(B.PART)=RTRIM(M.PART) AND RTRIM(B.PVAR)=RTRIM(M.PVAR) AND B.ARTST=M.ARTST)
WHERE EXISTS
(SELECT 1 FROM QVW_MCOST M WHERE  M.BS IN ('12','20','22','23','26','58')
AND RTRIM(B.SVDATE)=RTRIM(M.WDATE) AND B.LO=M.LO AND B.LB=M.LB
AND RTRIM(B.PART)=RTRIM(M.PART) AND RTRIM(B.PVAR)=RTRIM(M.PVAR) AND B.ARTST=M.ARTST)
GO

UPDATE QVW_MBST B SET MADJUST=
(SELECT SUM(UQTY) FROM QVW_MCOST M WHERE
M.BS NOT IN ('01','10','11','21','13','12','20','22','23','26','58') AND RTRIM(B.SVDATE)=RTRIM(M.WDATE) AND B.LO=M.LO AND B.LB=M.LB
AND RTRIM(B.PART)=RTRIM(M.PART) AND RTRIM(B.PVAR)=RTRIM(M.PVAR) AND B.ARTST=M.ARTST)
WHERE EXISTS
(SELECT 1 FROM QVW_MCOST M WHERE  M.BS NOT IN ('01','10','11','21','13','12','20','22','23','26','58') AND RTRIM(B.SVDATE)=RTRIM(M.WDATE) AND B.LO=M.LO AND B.LB=M.LB
AND RTRIM(B.PART)=RTRIM(M.PART) AND RTRIM(B.PVAR)=RTRIM(M.PVAR) AND B.ARTST=M.ARTST)
GO

UPDATE QVW_FBST B SET MOVEIN=
(SELECT SUM(UQTY) FROM QVW_MCOST M WHERE
M.BS IN ('01','10','11','21','13')  AND RTRIM(B.SVDATE)=RTRIM(M.WDATE) AND B.LO=M.LO AND B.LB=M.LB
AND RTRIM(B.PART)=RTRIM(M.PART) AND RTRIM(B.PVAR)=RTRIM(M.PVAR) AND RTRIM(B.PCOLOR)=RTRIM(M.PCOLOR) AND RTRIM(B.PSIZE)=RTRIM(M.PSIZE)AND B.ARTST=M.ARTST)
WHERE EXISTS
(SELECT 1 FROM QVW_MCOST M WHERE  M.BS IN ('01','10','11','21','13') AND RTRIM(B.SVDATE)=RTRIM(M.WDATE) AND B.LO=M.LO AND B.LB=M.LB
AND RTRIM(B.PART)=RTRIM(M.PART) AND RTRIM(B.PVAR)=RTRIM(M.PVAR) AND RTRIM(B.PCOLOR)=RTRIM(M.PCOLOR) AND RTRIM(B.PSIZE)=RTRIM(M.PSIZE)AND B.ARTST=M.ARTST)
GO

UPDATE QVW_FBST B SET MOVEOUT=
(SELECT SUM(UQTY) FROM QVW_MCOST M WHERE
M.BS IN ('12','20','22','23','26','58') AND RTRIM(B.SVDATE)=RTRIM(M.WDATE) AND B.LO=M.LO AND B.LB=M.LB
AND RTRIM(B.PART)=RTRIM(M.PART) AND RTRIM(B.PVAR)=RTRIM(M.PVAR) AND RTRIM(B.PCOLOR)=RTRIM(M.PCOLOR) AND RTRIM(B.PSIZE)=RTRIM(M.PSIZE)AND B.ARTST=M.ARTST)
WHERE EXISTS
(SELECT 1 FROM QVW_MCOST M WHERE  M.BS IN ('12','20','22','23','26','58')
AND RTRIM(B.SVDATE)=RTRIM(M.WDATE) AND B.LO=M.LO AND B.LB=M.LB
AND RTRIM(B.PART)=RTRIM(M.PART) AND RTRIM(B.PVAR)=RTRIM(M.PVAR) AND RTRIM(B.PCOLOR)=RTRIM(M.PCOLOR) AND RTRIM(B.PSIZE)=RTRIM(M.PSIZE)AND B.ARTST=M.ARTST)
GO

UPDATE QVW_FBST B SET MADJUST=
(SELECT SUM(UQTY) FROM QVW_MCOST M WHERE
M.BS NOT IN ('01','10','11','21','13','12','20','22','23','26','58') AND RTRIM(B.SVDATE)=RTRIM(M.WDATE) AND B.LO=M.LO AND B.LB=M.LB
AND RTRIM(B.PART)=RTRIM(M.PART) AND RTRIM(B.PVAR)=RTRIM(M.PVAR) AND RTRIM(B.PCOLOR)=RTRIM(M.PCOLOR) AND RTRIM(B.PSIZE)=RTRIM(M.PSIZE)AND B.ARTST=M.ARTST)
WHERE EXISTS
(SELECT 1 FROM QVW_MCOST M WHERE  M.BS NOT IN ('01','10','11','21','13','12','20','22','23','26','58') AND RTRIM(B.SVDATE)=RTRIM(M.WDATE) AND B.LO=M.LO AND B.LB=M.LB
AND RTRIM(B.PART)=RTRIM(M.PART) AND RTRIM(B.PVAR)=RTRIM(M.PVAR) AND RTRIM(B.PCOLOR)=RTRIM(M.PCOLOR) AND RTRIM(B.PSIZE)=RTRIM(M.PSIZE)AND B.ARTST=M.ARTST)
GO

UPDATE QVW_BABST B SET MOVEIN=
(SELECT SUM(UQTY) FROM QVW_MCOST M WHERE
M.BS IN ('01','10','11','21','13')  AND RTRIM(B.SVDATE)=RTRIM(M.WDATE) AND B.LO=M.LO AND B.LB=M.LB
AND RTRIM(B.PART)=RTRIM(M.PART) AND RTRIM(B.PVAR)=RTRIM(M.PVAR)AND RTRIM(B.PCOLOR)=RTRIM(M.PCOLOR)AND B.ARTST=M.ARTST)
WHERE EXISTS
(SELECT 1 FROM QVW_MCOST M WHERE  M.BS IN ('01','10','11','21','13') AND RTRIM(B.SVDATE)=RTRIM(M.WDATE) AND B.LO=M.LO AND B.LB=M.LB
AND RTRIM(B.PART)=RTRIM(M.PART) AND RTRIM(B.PVAR)=RTRIM(M.PVAR)AND RTRIM(B.PCOLOR)=RTRIM(M.PCOLOR)AND B.ARTST=M.ARTST)
GO

UPDATE QVW_BABST B SET MOVEOUT=
(SELECT SUM(UQTY) FROM QVW_MCOST M WHERE
M.BS IN ('12','20','22','23','26','58') AND RTRIM(B.SVDATE)=RTRIM(M.WDATE) AND B.LO=M.LO AND B.LB=M.LB
AND RTRIM(B.PART)=RTRIM(M.PART) AND RTRIM(B.PVAR)=RTRIM(M.PVAR)AND RTRIM(B.PCOLOR)=RTRIM(M.PCOLOR)AND B.ARTST=M.ARTST)
WHERE EXISTS
(SELECT 1 FROM QVW_MCOST M WHERE  M.BS IN ('12','20','22','23','26','58')
AND RTRIM(B.SVDATE)=RTRIM(M.WDATE) AND B.LO=M.LO AND B.LB=M.LB
AND RTRIM(B.PART)=RTRIM(M.PART) AND RTRIM(B.PVAR)=RTRIM(M.PVAR)AND RTRIM(B.PCOLOR)=RTRIM(M.PCOLOR)AND B.ARTST=M.ARTST)
GO

UPDATE QVW_BABST B SET MADJUST=
(SELECT SUM(UQTY) FROM QVW_MCOST M WHERE
M.BS NOT IN ('01','10','11','21','13','12','20','22','23','26','58') AND RTRIM(B.SVDATE)=RTRIM(M.WDATE) AND B.LO=M.LO AND B.LB=M.LB
AND RTRIM(B.PART)=RTRIM(M.PART) AND RTRIM(B.PVAR)=RTRIM(M.PVAR)AND RTRIM(B.PCOLOR)=RTRIM(M.PCOLOR)AND B.ARTST=M.ARTST)
WHERE EXISTS
(SELECT 1 FROM QVW_MCOST M WHERE  M.BS NOT IN ('01','10','11','21','13','12','20','22','23','26','58') AND RTRIM(B.SVDATE)=RTRIM(M.WDATE) AND B.LO=M.LO AND B.LB=M.LB
AND RTRIM(B.PART)=RTRIM(M.PART) AND RTRIM(B.PVAR)=RTRIM(M.PVAR)AND RTRIM(B.PCOLOR)=RTRIM(M.PCOLOR)AND B.ARTST=M.ARTST)
GO
UPDATE QVW_WBBST SET MSTQTY=STLENG-(MOVEIN-MOVEOUT-MADJUST) WHERE  STLENG-(MOVEIN-MOVEOUT-MADJUST) >0
GO
UPDATE QVW_GLLG SET MSTQTY=STWEIGHT-(MOVEIN-MOVEOUT-MADJUST) WHERE  STWEIGHT-(MOVEIN-MOVEOUT-MADJUST) >0
GO
UPDATE QVW_MBST SET MSTQTY=STWEIGHT-(MOVEIN-MOVEOUT-MADJUST) WHERE  STWEIGHT-(MOVEIN-MOVEOUT-MADJUST) >0
GO
UPDATE QVW_FBST SET MSTQTY=STWEIGHT-(MOVEIN-MOVEOUT-MADJUST) WHERE  STWEIGHT-(MOVEIN-MOVEOUT-MADJUST) >0
GO
UPDATE QVW_BABST SET MSTQTY=STLENG-(MOVEIN-MOVEOUT-MADJUST) WHERE  STLENG-(MOVEIN-MOVEOUT-MADJUST) >0
GO

